<%-- 
    Document   : update1
    Created on : 2014/8/19, 下午 04:44:10
    Author     : gjun
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String id=request.getParameter("id");
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb", "root", "root");
    Statement st=con.createStatement();
    String sql="select id, username, tel, birthday from person where id="+id;
    System.out.println(sql);
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            ResultSet rs=st.executeQuery(sql);//游標概念，從0(第一筆)開始，每筆只讀一次
            if(rs.next()){//游標往下一筆
                String username=rs.getString("username");
                String tel=rs.getString("tel");
                String birthday=rs.getString("birthday");
                //out.println(id+","+username+","+tel+","+birthday+"<br>");                     
        %>
        <form action="update2.jsp">
            username:<input type="text" name="username" maxlength="10" size="19" value="<%=username%>"><br>
            tel:<input type="text" name="tel" maxlength="15" size="26" value="<%=tel%>"><br>
            birthday:<input type="text" name="birthday" maxlength="10" value="<%=birthday%>"><br>
            <input type="hidden" name="id" value="<%=id%>">
            <input type="submit" value="確定送出">
        </form>   
        <%    
            }else{
                out.print("查無資料");
            }
            rs.close();
            st.close();
            con.close();
        %>
    </body>
</html>
